<?php

define(C("ACCESSACTION"), true);
import('jinghuan.AdminAction');

/**
 * Class SchoolVideoAction
 */
class ApkAction extends AdminAction
{

    function datatable()
    {
        $page = I('post.page');
        $length = I('post.length');
        $order = I('post.order');
        $echo = I('post.echo');
        $where = I('post.where');


        $count = D(JH_UPDATE)->where($where)->count();
        $row = D(JH_UPDATE)
            ->page($page, $length)
            ->where($where)
            ->order('id desc')
            ->select();

        $this->callback(array(
            'rows' => $row,
            'echo' => $echo,
            'count' => $count
        ));
    }

    function edit()
    {
        $post = I('post.');
        $result = D(JH_UPDATE)->find($post['id']);

        $this->callback($result);
    }

    function do_edit()
    {
        $post = I('post.');
        $admin_user_id = $_SESSION['admin_user_id'];

        D(JH_UPDATE)->save(array(
            'id' => $post['id'],
            "name" => $post['name'],
            "version" => $post['version'],
            "url" => $post['url'],
            "remark" => $post['remark'],
            'u_time' => time(),
            'user_id' => $admin_user_id
        ));

        $data = D(JH_UPDATE)->where(array('id' => $post['id']))->find();
        $this->callback($data);
    }

    /**
     *
     */
    function do_add()
    {
        $post = I('post.');
        $admin_user_id = $_SESSION['admin_user_id'];

        $result = D(JH_UPDATE)->add(array(
            "name" => $post['name'],
            "version" => $post['version'],
            "url" => $post['url'],
            "remark" => $post['remark'],
            "time" => time(),
            "u_time" => time(),
            "user_id" => $admin_user_id
        ));

        $this->callback($result != false);
    }

    /**
     * 删除
     */
    function do_delete()
    {
        $id = I('post.id');
        $row = D(JH_UPDATE)
            ->where(array('id' => $id))
            ->delete();

        if ($row === false) {
            $this->callback(false);
            return;
        }

        $this->callback(true);
    }
}